﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Globalization;
using System.Text.RegularExpressions;
using FinPlusCommon;
using u = FinPlusUtility.Utility;
using log = Logger.Logger;

namespace FinPlusWPFControls
{
    public partial class FinPlusValueTriState : FinPlusControl
    {
        public override string Id { get { return GetValue(IdProperty).ToString(); } set { } }
        public override string[] States { get { return new string[] { "ModelTest", "ViewTest", "IsValid" }; } }
        public override string[] TestStates { get { return new string[] { }; } }
        public override IFinPlusFunctions Model { get { return null; } }
        public override string ModelTest { get { return ModelToString(); } }
        public override bool IsValid { get; set; }

        public string ViewTest { get { return ToString(); } }

        public string FunctionName { get { return GetValue(FunctionNameProperty).ToString(); } set { } }
        public int State { get { return (int)GetValue(StateProperty); } set { SetValue(StateProperty, value); } }

        public static readonly DependencyProperty IdProperty = DependencyProperty.Register(Propertys.Id.ToString(), typeof(string), typeof(FinPlusValueTriState));
        public static readonly DependencyProperty FunctionNameProperty = DependencyProperty.Register(Propertys.FunctionName.ToString(), typeof(string), typeof(FinPlusValueTriState));
        public static readonly DependencyProperty StateProperty = DependencyProperty.Register(Propertys.State.ToString(), typeof(int), typeof(FinPlusValueTriState), new UIPropertyMetadata(Callback));

        private enum Propertys { Id, FunctionName, State }

        //construct
        public FinPlusValueTriState()
        {
            InitializeComponent();
            IsValid = true;
        }

        //common control interface
        public override void Dock(object control, string dock)
        {
            IsValid = false;
            throw new NotImplementedException();
        }

        public override void Initialise()
        {

        }

        public override void CommandRouter(IFinPlusFunction func) { }

        public override void Dispose(){}

        //public
        private void SetControl(DependencyPropertyChangedEventArgs a)
        {

        }

        public new string ToString()
        {
            return string.Format("{0}|{1}", State.ToString());
        }

        public string ModelToString()
        {
            return string.Format("{0}|{1}", IsEnabled, State.ToString());
        }

        //events
        private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs a) { ((FinPlusValueTriState)d).SetControl(a); ; }
    }
}